package com.book.common.lang;

/**
 * Description：元组类
 * @Author： leo.xiong
 * @CreateDate： 2020/4/15 10:31
 * @Email： leo.xiong@suyun360.com
 * Version：1.0
 */
public abstract class Tuple {

    public static <T1> Tuple1<T1> apply(T1 t1) {
        return new Tuple1<>(t1);
    }

    public static <T1, T2> Tuple2<T1, T2> apply(T1 t1, T2 t2) {
        return new Tuple2<>(t1, t2);
    }

    public static <T1, T2, T3> Tuple3<T1, T2, T3> apply(T1 t1, T2 t2, T3 t3) {
        return new Tuple3<>(t1, t2, t3);
    }

    public static <T1, T2, T3, T4> Tuple4<T1, T2, T3, T4> apply(T1 t1, T2 t2, T3 t3, T4 t4) {
        return new Tuple4<>(t1, t2, t3, t4);
    }

    public static <T1, T2, T3, T4, T5> Tuple5<T1, T2, T3, T4, T5> apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) {
        return new Tuple5<>(t1, t2, t3, t4, t5);
    }

    public <T1, T2> Tuple2<T2, T1> swap(Tuple2<T1, T2> tuple2) {
        return apply(tuple2._2(), tuple2._1());
    }

    public <T1, T2, T3> Tuple3<T3, T2, T1> swap(Tuple3<T1, T2, T3> tuple3) {
        return apply(tuple3._3(), tuple3._2(), tuple3._1());
    }

    public <T1, T2, T3, T4> Tuple4<T4, T3, T2, T1> swap(Tuple4<T1, T2, T3, T4> tuple4) {
        return apply(tuple4._4(), tuple4._3(), tuple4._2(), tuple4._1());
    }

    public <T1, T2, T3, T4, T5> Tuple5<T5, T4, T3, T2, T1> swap(Tuple5<T1, T2, T3, T4, T5> tuple5) {
        return apply(tuple5._5(), tuple5._4(), tuple5._3(), tuple5._2(), tuple5._1());
    }

}
